﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Proxies;
using CYTS.Aoyou.Framework.Config;

namespace CYTS.Aoyou.Framework.Core
{
    /// <summary>
    /// AOP特性, 标识在进行AOP策略的类上
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class AOPAttribute : ProxyAttribute
    {
        public override MarshalByRefObject CreateInstance(Type type)
        {
            MarshalByRefObject obj = base.CreateInstance(type);
            AOPConfig config = ConfigFactory.GetConfig<AOPConfig>();
            if (config.Enabled)
            {
                AOPProxy realProxy = new AOPProxy(type, obj);
                return realProxy.GetTransparentProxy() as MarshalByRefObject;
            }

            return obj;
        }
    }
}
